<template>
<!--包时套餐-->
<view class="community">
	<view class="head_bg"></view>
	<view class="big_box" style="margin-top:-160rpx;">
		<view class="count_tab">
			<view :class="{count_tab_inner: istrue == true,is_active: tabIndex == 1}" @tap="tabSelect" :data-id="1" style="margin-left: 100rpx;">全部</view>
			<view :class="{count_tab_inner: istrue == true,is_active: tabIndex == 2}" @tap="tabSelect" :data-id="2">使用中</view>
			<view :class="{count_tab_inner: istrue == true,is_active: tabIndex == 3}" @tap="tabSelect" :data-id="3" style="margin-right: 100rpx;">已过期</view>
		</view>
		<view>
			<view v-for="(info,index) in list" :key="index">
				<view v-if="info.is_over=='0'" class="package"  @tap="toTimeInfo(info)">
					<view class="flex">
						<view class="flex-sub">
							<view class="time_name text-white">{{info.package_name}}</view>
							<view class="text-white time_mon">¥<text>{{info.package_price}}</text></view>
						</view>
						<view class="flex-sub text-right">
							<view class="time_time text-white">{{info.begin_time.substring(0,10)}} 至 {{info.begin_time.substring(0,10)}}</view>
							<view class="time_add margin-top-xs time_add_color">{{info.residential_quarters_name}}</view>
							<view class="time_add time_add_color">仅限本小区使用</view>
						</view>
					</view>
					<view class="operating_box_inner">
						<view class="money_details_inner money_details_inner1">
							<view class="money_details_number time_add_color">{{info.charging_num}}</view>
							<view class="money_details_text time_add_color">总充电(次)</view>
						</view>
						<view class="detail_br" style="border-left: 1rpx solid #EDEDED;position: relative;top: 25rpx;"></view>
						<view class="money_details_inner money_details_inner1">
							<view class="money_details_number time_add_color">{{info.charging_time}}</view>
							<view class="money_details_text time_add_color">每次充电（小时）</view>
						</view>
						<view class="detail_br" style="border-left: 1rpx solid #EDEDED;position: relative;top: 25rpx;"></view>
						<view class="money_details_inner money_details_inner1">
							<view class="money_details_number time_add_color">{{info.surplus_num}}</view>
							<view class="money_details_text time_add_color">剩余（次）</view>
						</view>
					</view>
				</view>
				<view v-else class="package_gq" @tap="toTimeInfo(info)">
					<view class="flex">
						<view class="flex-sub">
							<view class="time_name text-white">{{info.package_name}}</view>
							<view class="text-white time_mon">¥<text>{{info.package_price}}</text></view>
						</view>
						<view class="flex-sub text-right">
							<view class="time_time text-white ">已过期</view>
							<view class="time_add margin-top-xs text-white">{{info.residential_quarters_name}}</view>
							<view class="time_add text-white">仅限本小区使用</view>
						</view>
					</view>
					<view class="operating_box_inner">
						<view class="money_details_inner money_details_inner1">
							<view class="money_details_number time_black">{{info.charging_num}}</view>
							<view class="money_details_text time_black">总充电(次)</view>
						</view>
						<view class="detail_br" style="border-left: 1rpx solid #EDEDED;position: relative;top: 25rpx;"></view>
						<view class="money_details_inner money_details_inner1">
							<view class="money_details_number time_black">{{info.charging_time}}</view>
							<view class="money_details_text time_black">每次充电（小时）</view>
						</view>
						<view class="detail_br" style="border-left: 1rpx solid #EDEDED;position: relative;top: 25rpx;"></view>
						<view class="money_details_inner money_details_inner1">
							<view class="money_details_number time_black">3</view>
							<view class="money_details_text time_black">剩余（次）</view>
						</view>
					</view>
				</view>
			</view>
			<view style="height:100rpx;"></view>
			<view v-if="list.length==0" class="margin-top-lg text-center">
				<image src='../../../common/img/no_data.png' style="width:275rpx;height:312rpx;"></image>
			</view>
			<view v-if="list.length>0" class="text-black text-df text-center bg-white padding-sm padding-left-lg be-gray">
				{{loadingTxt}} 共({{list.length}}条记录)
			</view>
		</view>
	</view>
</view>
</template>

<script>
	let page=1,timer=null
	export default {
		data() {
			return {
				info:'',
				tabIndex: 1,
				istrue: true,
				list:[],
				loadingTxt:'加载更多',
			}
		},
		onShow() {
			page=1;
			this.gatlist();
		},
		methods: {
			tabSelect(e) {
				page=1;
				this.loadingTxt="加载更多"
				this.tabIndex = e.currentTarget.dataset.id;
				this.gatlist();
			},
			toTimeInfo(info){
				uni.navigateTo({
					url:"/pages/user/package/package_timeinfo?info="+JSON.stringify(info)
				})
			},
			gatlist(){
				let that=this;
				let type;
				if(this.tabIndex==1){//is_over 字符串 0 全部 1 未过期 2已过期
					type="0";
				}else if(this.tabIndex==2){
					type="1";
				}else{
					type="2";
				}
				that.http.tokenreq({
					url:"user/v1/mysetmeal",
					data:{"is_over":type,"pageindex":page}
				}).then((res) => {
					let e=res.data;
					if(e.code==0 && e.success){
						let list=e.rows;
						that.list=list;
						page++;
					}else{
						uni.showModal({
							content:e.message,
							showCancel:false,
						})
					}
				})
			},
			getmorelist(){
				this.loadingTxt='加载中'
				let that=this;
				let type;
				if(this.tabIndex==1){//is_over 字符串 0 全部 1 未过期 2已过期
					type="0";
				}else if(this.tabIndex==2){
					type="1";
				}else{
					type="2";
				}
				that.http.tokenreq({
					url:"user/v1/mysetmeal",
					data:{"is_over":type,"pageindex":page}
				}).then((res) => {
					// console.log("res="+JSON.stringify(res));
					let e=res.data;
					if(e.code==0 && e.success){
						if(e.rows.length==0){
							that.loadingTxt="已经加载全部";
							return;
						}
						that.list=that.list.concat(e.rows);
						page++;
					}else{
						uni.showModal({
							content:e.message,
							showCancel:false,
						})
					}
				})
			},
			onReachBottom() {
				//阻止重复加载
				if(timer !== null){
					clearTimeout(timer)
				}
				timer=setTimeout(()=>this.getmorelist(),500)
			},
		}
	}
</script>
<style>
	.ele_title_inner{
		color: #FFFFFF;
		font-size:36rpx;
	}
	.package{
		background-image: url(../../../common/img/ka2.png);
		background-size: 100% 100%;
		width: 100%;
		height: 400rpx;
	}
	.package_gq{
		background-image: url(../../../common/img/ka3.png);
		width: 100%;
		background-size: 100% 100%;
		height: 400rpx;
	}
	.time_name{
		padding: 20rpx 0 0rpx 40rpx;
		font-size: 30rpx;
	}
	.time_mon{
		padding: 0 0 0 40rpx;
		font-size: 40rpx;
	}
	.time_time{
		padding: 57rpx 30rpx 0 0rpx;
	}
	.time_add{
		padding: 0rpx 30rpx 0 0;
	}
	.time_add_color{
		color:#8C6B22
	}
	.time_black{
		color: #666666 !important;
	}
</style>